package com.leetcode.LC;

import java.util.Arrays;
import java.util.List;

public class LC345 {
    //头尾指针，遇到元音对调
    public String reverseVowels(String s) {

        char[] chars = s.toCharArray();
        List<Character> list = Arrays.asList('a', 'e', 'i', 'o', 'u','A', 'E', 'I', 'O', 'U');
        int a=0,b=s.length()-1;
        char tmp;
        while (a<=b){
            if (list.contains(chars[a])&&list.contains(chars[b])){
                tmp=chars[a];
                chars[a]=chars[b];
                chars[b]=tmp;
                a++;
                b--;
            }else if (!list.contains(chars[a])&&!list.contains(chars[b])){
                a++;
                b--;
            }else if(list.contains(chars[a])&&!list.contains(chars[b])){
                b--;
            }else if(!list.contains(chars[a])&&list.contains(chars[b])){
                a++;
            }
        }
        return new String(chars);
    }

    public static void main(String[] args) {
        System.out.println(new LC345().reverseVowels("leetcode"));
    }
}
